const $upDate = require('./common/update.js');
require('./config/config.js'); // 全局配置       wx.$config
require('./common.js');
require('./api/api.js');
require('./common/methods.js')(wx) // 注册全局事件
require('./common/common.js'); // 注册全局方法
App({
  onLaunch: async function() {
    wx.setEnableDebug({ enableDebug: true })
    await this.getOpenId();
    if (wx.getUpdateManager) {
      const updateManager = await wx.getUpdateManager()
      try {
        $upDate(updateManager)
      } catch (e) {
        throw "更新错误"
      }
    }
    let {
      isCharging,
      level
    } = wx.getBatteryInfoSync();
    wx.setStorageSync('isCharging', isCharging); // 是否在充电
    wx.setStorageSync('level', level); // 电量百分比
  },
  globalData: {
    userInfo: null
  },
  getOpenId() {
    let that = this;
    return  new Promise((reslove, reject) => {
      wx.login({
        success: code => {
          wx.$api.login(code).then( (res) => {
            if (res.data.code == 200) {
              wx.setStorageSync('is_bind', res.data.data.is_bind);
              wx.setStorageSync('is_contract', res.data.data.is_contract);
              wx.setStorageSync('token', res.data.data.token+' *01');
              wx.setStorageSync('professional_id', res.data.data.userinfo.professional_id);
              wx.setStorageSync('mobile', res.data.data.userinfo.mobile);
              wx.setStorageSync('is_auth', res.data.data.is_auth);
              
              console.log('come herehere  appjs');
            }
            reslove();

          })
        }
      })
    })

    
  },
  // 验证是否绑定手机号  是否签署

  verify(){},
  config: {

  }
})